package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.DirectlyExecuteDTO;
import com.lyf.scm.admin.api.dto.DirectlyExecuteInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.DirectlyExecuteRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *         直营预测计划--执行
 * @author: haodong
 * @data: 2020/8/5 13:44
 */
@Service
@Slf4j
public class DirectlyExecuteFacade {

    @Resource
    private DirectlyExecuteRemote directlyExecuteRemote;

    /**
     * 按条件查询直营预测计划
     * @param salesPlanDirectlyExecute
     * @return
     */
    public PageInfo<DirectlyExecuteInfoDTO> listBySelective(DirectlyExecuteDTO salesPlanDirectlyExecute) {
        log.info("按条件查询直营预测计划入参:DirectlyExecuteDTO:{}", JSON.toJSONString(salesPlanDirectlyExecute));
        Response<PageInfo<DirectlyExecuteInfoDTO>> response = directlyExecuteRemote.listBySelective(salesPlanDirectlyExecute);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 查询全渠道直营预测计划
     * @param salesPlanDirectlyExecute
     * @return
     */
    public List<DirectlyExecuteInfoDTO> listAllByDays(DirectlyExecuteDTO salesPlanDirectlyExecute) {
        log.info("查询全渠道直营预测计划入参:DirectlyExecuteDTO:{}", JSON.toJSONString(salesPlanDirectlyExecute));
        Response<List<DirectlyExecuteInfoDTO>> response = directlyExecuteRemote.listAllByDays(salesPlanDirectlyExecute);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 导出Excel
     * @param directly
     * @param type
     * @return
     */
    public feign.Response exportExcel(DirectlyExecuteDTO directly, Integer type) {
        log.info("导出Excel入参:SalesPlanDirectlyDTO:{}", JSON.toJSONString(directly));
        return directlyExecuteRemote.exportExcel(directly, type);
    }

    public void delete(String opSign) {
        log.info("删除直营预测——执行对应标识:{}", JSON.toJSONString(opSign));
        directlyExecuteRemote.delete(opSign);
    }

}
